<template>
	<view class="personal">
		<view class="title">
			<text class="text">我的</text>
			<image class="set-btn" src="/static/user/set.png" @click="personalInfo()" mode="aspectFill"></image>
		</view>
		<view class="stu-info">
			<view class="head">
				<image :src="utils.headImage(studentInfo)" @click="utils.userDetails(studentInfo.accountId, studentInfo.userType)" mode="aspectFill"></image>
			</view>
			<view class="name">{{studentInfo.name}}</view>
		</view>
		<view class="module-list">

			<view class="module-item flex" @click="pageJump(item)" v-for="(item, index) in module_list1" :key="index">
				<view class="left">
					<image class="icon-img" :src="`/static/user/${item.icon}.png`" mode="aspectFit"></image>
					<text class="name">{{item.text}}</text>
				</view>
				<view>
					<text v-if="item.icon=='zytr'&& (task_overdue>0 || exampleNeedRefine || taskNeedRefine)" class="tips">{{task_overdue==1?'任务已过期':task_overdue==2?'任务即将到期':taskNeedRefine?'完善重要他人任务':'完善重要他人信息'}}</text>
					
					<uni-icons type="right" size="32rpx" color="#999"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onShow(){
			this.getMeInfo();
			this.getDeadLine()
		},
		data(){
			return {
				studentInfo: {},
				module_list1: [{icon: 'zycs', text: '自我认知', url: '/pages/MBTI/test-home'}, {icon: 'zytr', text: '重要他人', url: '/pages/student/create-example'}, {icon: 'xnkjx', text: '虚拟空间秀'}, {icon: 'wdsc', text: '我的收藏'}, {icon: 'wdfb', text: '我的发布', url: '/pages/student/my-publish'}, {icon: 'bdds', text: '绑定导师', url: '/pages/student/bind-history'}, {icon: 'bd', text: '榜单', url: '/pages/student/list-ranking'}, {icon: 'wdkc', text: '我的课程', url: '/pages/personalInfo/my-course'}],

				task_overdue: false,
				taskNeedRefine: false,
				exampleNeedRefine: false
			}
		},
		methods: {
			getDeadLine(){
				this.api.get('sExample/findExampleDeadLine').then(res=>{
					if(res.data.state == 'ok'){
						let info = res.data;
						this.task_overdue = info.overdue;
						this.taskNeedRefine = info.taskNeedRefine;

						this.exampleNeedRefine = info.exampleNeedRefine;
					}
				})
			},
			getMeInfo(){
				this.api.get('user/getMeInfo').then(res=>{
					this.studentInfo = res.data.user;
					getApp().globalData.userInfo = this.studentInfo
				})
			},
			pageJump(item){
				if(!item.url){
					uni.showToast({
						title: '功能待开发',
						duration: 2000,
						icon: 'none',
						mask: true,
						position: 'bottom'
					})
					return;
				}
				if(item.icon=='zytr'){
					if(this.task_overdue==0 && !this.exampleNeedRefine && !this.taskNeedRefine){
						uni.navigateTo({
							url: '/pages/student/example-details'
						})
					}else{
						let overdue = this.task_overdue>0?1:'';
						if(!overdue){
							overdue = this.taskNeedRefine?2:'';
						}
						let needRefine = this.exampleNeedRefine?1:'';
						uni.navigateTo({
							url: '/pages/student/create-example?overdue='+overdue +'&needRefine=' + needRefine
						})
					}
					
					return
				}
				if(item.icon == 'wdfb'){
					uni.navigateTo({
						url: `${item.url}?accountId=${this.studentInfo.accountId}`
					})
					return
				}
				if(item.params>=0){
					getApp().globalData.taskPageIndex = item.params;
				}
				
				if(item.type=='tabBar'){
					uni.switchTab({
						url: item.url
					})
				}else{
					uni.navigateTo({
						url: item.url
					})
				}
				
			},
			closePopup(){
				this.show_qrcode = false;
			},
			personalInfo(){
				let avatarUrl = this.studentInfo.avatarUrl || ''
				uni.navigateTo({
					url: '/pages/personalInfo/personal-info?head='+avatarUrl+'&sex='+this.studentInfo.sex
				})
			}
		}
	}
</script>
<style lang="less" scoped>
	
	.personal{
		overflow: hidden;
		padding: 0rpx 32rpx 40rpx;
		box-sizing: border-box;
		background-image: url('~@/static/user/bg.png');
		background-repeat: no-repeat;
		background-size: contain;
		background-position: 0 0;
		box-sizing: border-box;
	}
	.title{
		padding: 16rpx 0;
		// #ifdef APP-PLUS
		padding-top: calc(16rpx + 28px);
		// #endif
		display: flex;
		justify-content: space-between;
		align-items: center;
		.text{
			font-size: 46rpx;
			color: #262E3F;
			font-weight: bold;
		}
	}
	.set-btn{
		width: 44rpx;
		height: 44rpx;
	}

	.uni-icons{
		margin-left: 16rpx;
	}
	.flex{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.stu-info{
		text-align: center;
		font-size: 0;
		padding-bottom: 32rpx;
		.head{
			image{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50rpx;
				border: 6rpx solid #fff;
				box-sizing: border-box;
			}
		}
		.name{
			margin-top: 20rpx;
			font-weight: 600;
			font-size: 34rpx;
			line-height: 48rpx;
			color: #333333;
		}
		.num{
			margin-top: 10rpx;
			color: #666666;
			font-size: 20rpx;
		}
	}

	.module-list {
		margin-top: 40rpx;
		.left{
			display: flex;
			align-items: center;
		}
		.tips{
			font-size: 32rpx;
			color: #999999;
		}

		
	}
	.icon-img {
		width: 60rpx;
		height: 60rpx;
		margin-right: 32rpx;
	}
	.module-item{
		font-size: 0;
		height: 104rpx;
		position: relative;
		&::after{
			position: absolute;
			left: 92rpx;
			bottom: 0;
			content: '';
			width: 200%;
			height: 2rpx;
			background-color: #EEEEEE;
			transform: scale(0.5) translateX(-50%);
			
		}
		.name{
			font-size: 34rpx;
			color: #333333;
		}
	}
</style>